HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/kevin-demo/wp-content/plugins/wpforms-sendinblue/src/Api/Http/Response.php
<?php

namespace WPFormsSendinblue\Api\Http;

/**
 * Wrapper class to parse responses.
 *
 * @since 1.0.0
 */
class Response {

	/**
	 * Input data.
	 *
	 * @since 1.0.0
	 *
	 * @var array
	 */
	private $input;

	/**
	 * Request constructor.
	 *
	 * @since 1.0.0
	 *
	 * @param array $input The response data.
	 */
	public function __construct( $input ) {

		$this->input = $input;
	}

	/**
	 * Retrieve only the response code from the raw response.
	 *
	 * @since 1.0.0
	 *
	 * @return int The response code as an integer.
	 */
	public function get_response_code() {

		return absint( wp_remote_retrieve_response_code( $this->input ) );
	}

	/**
	 * Retrieve only the response message from the raw response.
	 *
	 * @since 1.0.0
	 *
	 * @return string The response message.
	 */
	public function get_response_message() {

		$body = $this->get_body();

		if ( is_array( $body ) && ! empty( $body['message'] ) ) {
			return $body['message'];
		}

		$message = wp_remote_retrieve_response_message( $this->input );

		return ! empty( $message ) ? $message : 'Response error';
	}

	/**
	 * Retrieve only the body from the raw response.
	 *
	 * @since 1.0.0
	 *
	 * @return array The body of the response.
	 */
	public function get_body() {

		return json_decode( wp_remote_retrieve_body( $this->input ), true );
	}

	/**
	 * Whether we received errors in the response.
	 *
	 * @since 1.0.0
	 *
	 * @return bool True if response has errors.
	 */
	public function has_errors() {

		$code = $this->get_response_code();

		return $code < 200 || $code > 299;
	}
}